
  -- Update table '{{ table.name }}'
{# new columns -#}
{% for column in table.newColumns %}
  if funcAppColumnExists('{{ table.name }}', '{{ column.name }}') = 0 then
    insert into temp_app_upgrade_log(message) values ('create table column: {{ table.name }}.{{ column.name }}');
    ALTER TABLE {{ table.name }} ADD `{{ column.name }}` {{ column.type }}{{ " NOT NULL" if not column.nullable }}{{ " DEFAULT " + column.default if column.default }}{{ " COMMENT " + (column | getComment | toSQL) if withComment and (column | getComment) }}
    {%- if column.afterColumn -%}
    {{ " AFTER " + "`" + column.afterColumn + "`" }}
    {%- else -%};
    {{ " FIRST" }}
    {%- endif %};
  end if;
{% endfor -%}
{# new primary keys -#}
{% if table.newPrimaryKeys %}
  if funcAppPrimaryKeyExists('{{ table.name }}', '{{ table.newPrimaryKeys.columns }}') = 0 then
    insert into temp_app_upgrade_log(message) values ('create table primary key: {{ table.name }}:{{ table.newPrimaryKeys.columns }}');
    ALTER TABLE {{ table.name }} ADD CONSTRAINT PRIMARY KEY ({{ table.newPrimaryKeys.columns }});
  end if;
{% endif %}
{# new indexes -#}
{% for index in table.newIndexes %}
{{ ("index: " + index.columns) | log }}
{%- if index.unique %}
  if funcAppIndexExists('{{ table.name }}', '{{ index.columns }}') = 0 then
    insert into temp_app_upgrade_log(message) values ('create table index: {{ table.name }}:{{ index.columns }}');
    CREATE UNIQUE INDEX `{{ index.name }}` USING BTREE ON {{ table.name }} ({{ index.columns }});
  end if;
{% elif index.type === "FULLTEXT" %}
  if funcAppIndexExists('{{ table.name }}', '{{ index.columns }}') = 0 then
    insert into temp_app_upgrade_log(message) values ('create table index: {{ table.name }}:{{ index.columns }}');
    CREATE FULLTEXT INDEX `{{ index.name }}` USING BTREE ON {{ table.name }} ({{ index.columns }});
  end if;
{% else %}
  if funcAppIndexExists('{{ table.name }}', '{{ index.columns }}') = 0 then
    insert into temp_app_upgrade_log(message) values ('create table index: {{ table.name }}:{{ index.columns }}');
    CREATE INDEX `{{ index.name }}` USING BTREE ON {{ table.name }} ({{ index.columns }});
  end if;
{% endif %}
{% endfor %}
